<?php 
if (!isset($_SESSION)){session_start();}
require_once('Connections/tecno.php'); 
$id = $_REQUEST['id'];

$f=date('Y-m-d'); 

$insertSQL = "INSERT INTO contratos (idContrato, fechaContrato, status) VALUES ('', '$f','0')";								
mysql_select_db($database_tecno, $tecno);
$Result1 = mysql_query($insertSQL, $tecno) or die(mysql_error());
$id_c= mysql_insert_id();

	   $art = $_REQUEST['idArt'];
   $n        = count($art);
	   $i        = 0;
	   $sql_det = "idArt IN ("; 

		while ($i < $n){
			  if($n-$i==1){
				 $sql_det .= "'".$art[$i]."')"; 
			  }else{
				  $sql_det .= "'".$art[$i]."',";
		 		   }
				$i++; 
	     }
	$sql_det;


		$updateSQL = "UPDATE detallescliente SET idContrato= '$id_c' WHERE ". $sql_det;								
			mysql_select_db($database_tecno, $tecno);
			$Result1 = mysql_query($updateSQL, $tecno) or die(mysql_error());
$msj='';


if ($id_c>0){
$ipCli= $_SESSION["ipCliente"];
$login=	$_SESSION['usuario'];
///Bitacora del Sistema
$sql_det="Contrato Nro.".$id_c;

$fechaAud=date('y-m-d');
$horaAud=date('h:i:s:a');
///Bitacora del Sistema
$sqlBitacora ="INSERT INTO bitacora (host, usuario, operacion,  fecha, hora, tabla, detalle) VALUES ('$ipCli', '$login', 'INSERTAR','$fechaAud', '$horaAud', 'Contratos', '$sql_det')";
$Result1 = mysql_query($sqlBitacora, $tecno) or die(mysql_error());
}


?>

<?php 
require_once('Connections/tecno.php'); 
session_start();
require_once('scripts/fechaMysqlNormal.php');
$id = "-1";
if (isset($_REQUEST['id'])) {
  $id = $_REQUEST['id'];
}
mysql_select_db($database_tecno, $tecno);
$query_prod = "SELECT * FROM datospersonales WHERE id = '$id'";
$prod = mysql_query($query_prod, $tecno) or die(mysql_error());
$row_prod = mysql_fetch_assoc($prod);
$totalRows_prod = mysql_num_rows($prod);
?>
<link href="css/demo_jconfirmaction.css" rel="stylesheet" type="text/css" />
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="js/ui/ui.core.js"></script>
	<link type="text/css" href="../demos.css" rel="stylesheet" />
<div id="right" style="float:none;margin:0px;height:440px;width:750px;">
    <!--inicio div content-right -->
    <div id="content-right">
      <h2 style="text-align:center">Contratos</h2>
      <div class="form">
       	<h3 style="text-align:center;"><span style=" font-size:15px; font-weight:bold;">Cliente:</span>
        	  <?php echo $row_prod['cedula']." - ".$row_prod['primerApellido'].", ".$row_prod['nombres'];;?> &nbsp;&nbsp;
          <span style=" font-size:15px; font-weight:bold;">Credito Disponible:</span> &nbsp;<?php echo $row_prod['credito'];?> Bs.</h3>
</div>
      <div class="demo" style="text-align:center">	
<a href="reportes/contrato.php?id=<?php echo $id_c; ?>" target="_blank"><div id="guardarContrato" class="botonCustomMed" style="float:left;">Imprimir Contrato</div>
          </a>
<a href="crearContrato.php?id=<?php echo $row_prod['id']; ?>" ><div id="guardarContrato" class="botonCustomMed" style="float:left;">Continuar</div>
          </a>
          </div><!-- End demo -->                   
   <div class="ui-widget"></div>
<!--fin div content-right -->
</div>
